package com.jason.game.online.home.view

import android.content.Context
import cn.bingoogolapple.bgabanner.BGABanner
import com.cby.library.common.base.IViewSection
import com.cby.library.common.ext.showToast
import com.cby.library.data.model.BannerBean
import com.jason.game.online.R
import com.jason.game.online.home.adapter.BannerAdapter

/**
 * @description: HomeBannerViewSection
 *
 * @author ChenBaoyang
 * @date 2021/10/26 17:36
 */
class HomeBannerViewSection(context: Context) : IViewSection<List<BannerBean>>(context) {

    private lateinit var banner: BGABanner

    private lateinit var bannerAdapter: BannerAdapter

    override fun populateView() {
        banner = rootView.findViewById(R.id.banner)
        bannerAdapter = BannerAdapter(context)
        banner.setAdapter(bannerAdapter)
    }

    override fun getLayoutId() = R.layout.layout_header_banner

    override fun setData(data: List<BannerBean>) {
        banner.setData(data, null)
        banner.setDelegate { banner, itemView, model, position -> context.showToast(data[position].action) }
    }
}